package http.two2xx;

import http.MyHttpResponse;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author Karl
 * @Date 2023/1/9 - 15:13
 */
public class CacheResponse extends MyHttpResponse {
    public CacheResponse(File file) throws IOException {
        int len = 0;
        responseLine = "HTTP/1.1 200 CACHE_FROM_MY_PROXY";
//        responseHeader.put("Content-Type","Content-Type: text/html; charset=utf-8");
//        responseHeader.put("cache-control","cache-control: max-age=6000");
        InputStream html = null;
        html = new FileInputStream(file);
        int contentLength = html.available();
        responseHeader.put("Content-Length","Content-Length: "+contentLength);
        while((len = html.read())!=-1)
            addResponseBody((byte) len);

        html.close();

    }
}
